package com.lechuang.cunpinke.app;

import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.webkit.WebView;

import com.lechuang.cunpinke.BuildConfig;
import com.lechuang.cunpinke.db.DBManager;
import com.lechuang.cunpinke.db.DatabaseHelper;
import com.lechuang.cunpinke.manager.FolderManager;
import com.lechuang.cunpinke.network.Netword;
import com.lechuang.cunpinke.utils.CrashExceptionHandler;
import com.tencent.bugly.crashreport.BuglyLog;
import com.tencent.bugly.crashreport.CrashReport;


/**
 * 作者：尹松涛
 * 邮箱：yinsongtaoshmily@outlook.com
 * 日期：2017/9/4
 * 时间：14:08
 */

public class MyApplication extends Application {
    public static String TAG = MyApplication.class.getSimpleName();
    private static MyApplication instance;

    public static Context getContext() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        configCollectCrashInfo();
        Netword.init();
        DBManager.initializeInstance(new DatabaseHelper(instance));
        CrashReport.setAppChannel(this, BuildConfig.FLAVOR);
        CrashReport.initCrashReport(this, BuildConfig.CRASH_REPORT_ID, true);
        if (BuildConfig.DEBUG) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                WebView.setWebContentsDebuggingEnabled(true);
            }
        }
    }


    public static MyApplication getInstance() {
        return instance;
    }

    /**
     * 配置崩溃信息的搜集
     */
    private void configCollectCrashInfo() {
        CrashExceptionHandler crashExceptionHandler = new CrashExceptionHandler(this, FolderManager.getCrashLogFolder());
        Thread.setDefaultUncaughtExceptionHandler(crashExceptionHandler);
    }


}
